package com.qiangshi.tasksProgress.service.impl;

import com.qiangshi.common.utils.DateUtils;
import com.qiangshi.tasksProgress.domain.QsTasksProgress;
import com.qiangshi.tasksProgress.mapper.QsTasksProgressMapper;
import com.qiangshi.tasksProgress.service.IQsTasksProgressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 进度提报Service业务层处理
 *
 * @author qiangshi
 * @date 2022-02-12
 */
@Service
public class QsTasksProgressServiceImpl implements IQsTasksProgressService {
    @Autowired
    private QsTasksProgressMapper qsTasksProgressMapper;

    /**
     * 查询进度提报
     *
     * @param id 进度提报ID
     * @return 进度提报
     */
    @Override
    public QsTasksProgress selectQsTasksProgressById(Long id) {
        return qsTasksProgressMapper.selectQsTasksProgressById(id);
    }

    /**
     * 查询进度提报列表
     *
     * @param qsTasksProgress 进度提报
     * @return 进度提报
     */
    @Override
    public List<QsTasksProgress> selectQsTasksProgressList(QsTasksProgress qsTasksProgress) {
        return qsTasksProgressMapper.selectQsTasksProgressList(qsTasksProgress);
    }

    /**
     * 新增进度提报
     *
     * @param qsTasksProgress 进度提报
     * @return 结果
     */
    @Override
    public int insertQsTasksProgress(QsTasksProgress qsTasksProgress) {
        qsTasksProgress.setCreateTime(DateUtils.getNowDate());
        return qsTasksProgressMapper.insertQsTasksProgress(qsTasksProgress);
    }

    /**
     * 修改进度提报
     *
     * @param qsTasksProgress 进度提报
     * @return 结果
     */
    @Override
    public int updateQsTasksProgress(QsTasksProgress qsTasksProgress) {
        return qsTasksProgressMapper.updateQsTasksProgress(qsTasksProgress);
    }

    /**
     * 批量删除进度提报
     *
     * @param ids 需要删除的进度提报ID
     * @return 结果
     */
    @Override
    public int deleteQsTasksProgressByIds(Long[] ids) {
        return qsTasksProgressMapper.deleteQsTasksProgressByIds(ids);
    }

    /**
     * 删除进度提报信息
     *
     * @param id 进度提报ID
     * @return 结果
     */
    @Override
    public int deleteQsTasksProgressById(Long id) {
        return qsTasksProgressMapper.deleteQsTasksProgressById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean saveBatch(List<QsTasksProgress> qsTasksProgressList) {
        for (QsTasksProgress qsTasksProgress : qsTasksProgressList) {
            if (qsTasksProgressMapper.insertQsTasksProgress(qsTasksProgress) < 1) {
                return false;
            }
        }
        return true;
    }
}
